/*
 * @Author: 明月下
 * @Date: 2022-08-04 20:13:49
 * @LastEditors: 明月下
 * @LastEditTime: 2023-03-13 00:31:53
 * @FilePath: \ali-yun-slimming\vue3-vite\src\utils\request.ts
 * @Description:
 */
import axios from "axios";
import { Notify } from 'vant';

const service = axios.create({
    baseURL: '/express/',
    timeout: 5000
})
// 请求拦截器
service.interceptors.request.use(
    config => {
        // config.headers['request-startTime'] = new Date().getTime()
        return config
    },
    error => {
        // do something with request error
        console.log(error) // for debug
        return Promise.reject(error)
    }
)

// 响应拦截器
service.interceptors.response.use(
    response => {
        return response.data
    },
    error => {
        console.log('err' + error) // for debug
        Notify({ type: 'danger', message: error.message + ',请求超时了，请重新尝试', duration: 3000});
        return Promise.reject(error)
      }
)

export default service